import java.util.Scanner;

/**
 * @author gao
 * @date 2025/7/4 15:20
 */

public class Demo3 {

    // 加上volatile关键字之后
    private static volatile int flag = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            while (flag == 0) {
            }
            System.out.println("t1线程结束");
        });

        Thread t2 = new Thread(() -> {
            Scanner in = new Scanner(System.in);
            System.out.println("请输入flag的值:");
            flag = in.nextInt();
            System.out.println("t2线程结束");
        });

        t1.start();
        t2.start();

        t1.join();
        t2.join();
    }
}